/**
 * Created by Administrator on 2015/6/11.
 */
var db=require('./DbOperator');
var util = require('util');
var logging = require('../../lib/logging.js');
var log_level='DEBUG';
var logger = logging.getLogger('ShopInfoService','abc',log_level);
var ShopInfoService=function(){

}
ShopInfoService.prototype.updateImagesDownLoadStatus=function(id,imageLocal,status,reason){
    var sql="";
    if(reason!==undefined) {
        sql='update xbq_shop_info set imageDownLoadErrorReason="%s",imageDownLoadStatus="%s" where id=%s';
        //reason=reason.replace(new RegExp("'",'gm'),"\\'");
        sql=util.format(sql,reason,status,id);
        logger.error(sql);
    }
    else{
        sql="update xbq_shop_info set imageLocal='%s',imageDownLoadStatus='%s' where id=%s";
        sql=util.format(sql,imageLocal,status,id);
    }
    db.executeSql(sql);
};
ShopInfoService.prototype.getShopInfos=function(cb){
    var sql="SELECT	id,image,shopId,shopUrl FROM xbq_shop_info WHERE imageLocal IS  " +
        "NULL AND imageDownLoadStatus='0' AND image!='undefined' ORDER BY id DESC LIMIT 0,50";
    db.executeSqlCallback(sql,cb);
}
module.exports = exports=new ShopInfoService();
